home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10753 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: haystack.physio-control.com!usenet
  2. From: Brian Reese <breese@kahuna>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Converting Strings to Upper Case
  5. Date: Tue, 19 Mar 96 11:36:29 PDT
  6. Organization: Physio Control, Inc.
  7. Message-ID: <NEWTNews.827264485.11654.breese@PC_Breese.physio-control>
  8. References: <4ifra6$52i@scipio.cyberstore.ca> <4ih7l3$526@thrush.sover.net> <4ihl4m$4ca@castle.nando.net> <NEWTNews.827184423.14391.breese@PC_Breese.physio-control>  <314eb83f.308884702@nntp.ix.netcom.com>
  9. NNTP-Posting-Host: pc_breese.physio-control.com
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=US-ASCII
  12. X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage
  13.  
  14.  
  15. In article <314eb83f.308884702@nntp.ix.netcom.com>, <miker3@ix.netcom.com> 
  16. writes:
  17. > Brian Reese <breese@kahuna> wrote:
  18. > > Here's my offering:
  19. > > 
  20. > > #include <stdio.h>  /* for printf()  */
  21. > > #include <ctype.h>  /* for toupper() */
  22. > > 
  23. > > char * strtoupper( char * );  /* converts string to upper case */
  24. > > 
  25. > > int main( void )
  26. > > {
  27. > >     char * test = "my test string";
  28. > >     
  29. > >     printf( "%s\n", test );
  30. > >     printf( "%s\n", strtoupper( test ) );
  31. > >     
  32. > >     return 0;
  33. > > }
  34. > > 
  35. > > char * strtoupper( char * ptr )  /* converts string to upper case */
  36. > > {
  37. > >     char * save_ptr = ptr;   /* save pointer for return */
  38. > >     
  39. > >     while ( *ptr = toupper( *ptr++ ) )
  40. > >         ;
  41. > >     return save_ptr;
  42. > > }
  43. > Not a very good offering.  There are two obvious problems in your
  44. > example.
  45. > First, the identifier strtoupper with external linkage is reserved.
  46. > Defining your own function with external linkage with this name
  47. > results in undefined behavior.
  48. > Second, the expression
  49. >     *ptr = toupper( *ptr++ )
  50. > modifies ptr and also acesses its value other than to determine the
  51. > new value without an intervening sequence point.  This too results in
  52. > undefined behavior.
  53. > Michael M Rubenstein
  54.  
  55. Well, Michael, thanks for the corrections.  I did compile and run the
  56. above code before posting it, and it worked, but as you said, the
  57. behavior is undefined.  I got lucky (if you care to call that lucky).
  58.  
  59. Brian
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.